//当输入角色编码验证是否存在0存在  1 不存在 
function checkNo(roleNo){
		if(trim(roleNo)==""){
			alert("角色编码不能全为空格!!!");
			checkRoleNo = "false" ;
			return false;
		}	   
	   	if(roleNo!=""){
			$.ajax({
				url : path + '/role/role_checkNo',
				type : 'get',
				dataType : 'text',
				data : {"No":roleNo},
				error : function() {
				},
				success : function(result) {
					if(result=="200"){
						checkRoleNo = "true" ;	
					}else{
						layer.alert("角色编号已经存在！");
						checkRoleNo = "false" ;	
						return false;
					}
				}
			});	
		   	
		   }
	   } 
function save(){
    if(checkRoleNo=="false"){
		return;
    }
	var orgName =$("#name").val();
	var remark =$("#remark").val();
	var orgNon =$("#number").val();
	if(orgName.length==0 || trim(orgName).length == 0){
		layer.alert("角色名称不能为空！");
		window.orgAdmin.document.getElementById("name").focus();
		return;
	}
	if(remark.length==0 || trim(remark).length == 0){
		layer.alert("备注不能为空！");
		window.orgAdmin.document.getElementById("remark").focus();
		return;
	}
	//验证只包含字母或者汉字
	var pattern =/(^[\u4e00-\u9fa5A-Za-z0-9_-]*$)/;
	//验证不能为纯数字
	var patternNum=/^\d+$/;
	if (!pattern.test(orgName)) {
		layer.alert("请输入合法的角色名称！");
		return false;
	}
	if (patternNum.test(orgName)) {
		layer.alert("角色名称不能为纯数字！");
		return false;
	}

	if(orgNon.length==0 || trim(orgNon).length == 0){
		layer.alert("角色编码不能为空");
		return false;
	}
	var treeObj=$.fn.zTree.getZTreeObj("treeDemo");
    var nodes=treeObj.getCheckedNodes(true);
    v="";
    for(var i=0;i<nodes.length;i++){
    	if(i==nodes.length-1){
    		 v+=nodes[i].id;
    	}else{
    		 v+=nodes[i].id + ",";
    	}
   
    //获取选中节点的值
    }
    $("#ids").val(v);
    var layer_load_window = layer.load(2); 
    $("#form-role").ajaxSubmit({
		dataType : 'html',
        success: function(message){
        		if(message == "200"){
                    layer.msg('操作成功!',{icon:1,time:1000},function(){
/*                         var index = parent.layer.getFrameIndex(window.name);
                        parent.query_brand_form.submit();
                        parent.layer.close(index); */
                        parent.window.location.reload();
                    });
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        },complete: function(XMLHttpRequest, textStatus) {
        	layer.close(layer_load_window);
        }
    });
}
function add(){
	var zTree = parent.$.fn.zTree.getZTreeObj("treeDemo");
    var nodes = zTree.getSelectedNodes();
    var id=JSON.stringify(nodes[0].id);
	layer_show('添加资源',path+'/resource/resource_toadd?id='+id,'800','600');
}
function trim(str){ 
	 return str.replace(/(^\s*)|(\s*$)/g, "");
	}